#include <bits/stdc++.h>

using namespace std;

class Node
{
public:
    int val;
    vector<Node *> children;

    Node() {}

    Node(int _val)
    {
        val = _val;
    }

    Node(int _val, vector<Node *> _children)
    {
        val = _val;
        children = _children;
    }
};

class Solution
{
public:
    void recursion(Node* root,vector<int>& vec)
    {
        if(root==nullptr)
        {
            return ;
        }
        int length=root->children.size();
        for(int i=0;i<length;i++)
        {
            recursion(root->children[i],vec);
        }
        vec.push_back(root->val);
    }

    vector<int> postorder(Node *root)
    {
        vector<int> vec;
        recursion(root,vec);
        return vec;
    }
};

int main()
{
    Node *root = new Node(1);
    root->children.push_back(new Node(3));
    root->children.push_back(new Node(2));
    root->children.push_back(new Node(4));
    root->children[0]->children.push_back(new Node(5));
    root->children[0]->children.push_back(new Node(6));
    Solution sol;
    vector<int> res = sol.postorder(root);
    for (auto num : res)
    {
        cout << num << " ";
    }
    cout << endl;
}